namespace SumerCoreDevOps.Shared.Models;

/// <summary>
/// 统一 API 响应包装
/// </summary>
public class ApiResponse<T>
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool Success { get; set; }

    /// <summary>
    /// 响应数据
    /// </summary>
    public T? Data { get; set; }

    /// <summary>
    /// 错误消息
    /// </summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// 时间戳
    /// </summary>
    public long Timestamp { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

    public static ApiResponse<T> Ok(T? data = default)
    {
        return new ApiResponse<T>
        {
            Success = true,
            Data = data
        };
    }

    public static ApiResponse<T> Fail(string errorMessage)
    {
        return new ApiResponse<T>
        {
            Success = false,
            ErrorMessage = errorMessage
        };
    }
}

/// <summary>
/// 非泛型 API 响应辅助类
/// </summary>
public static class ApiResponse
{
    /// <summary>
    /// 创建成功响应
    /// </summary>
    public static ApiResponse<T> Ok<T>(T? data = default)
    {
        return ApiResponse<T>.Ok(data);
    }

    /// <summary>
    /// 创建成功响应（object 类型重载）
    /// </summary>
    public static ApiResponse<object?> Ok(object? data)
    {
        return ApiResponse<object?>.Ok(data);
    }

    /// <summary>
    /// 创建失败响应
    /// </summary>
    public static ApiResponse<T> Fail<T>(string errorMessage)
    {
        return ApiResponse<T>.Fail(errorMessage);
    }

    /// <summary>
    /// 创建失败响应（object 类型重载）
    /// </summary>
    public static ApiResponse<object?> Fail(string errorMessage)
    {
        return ApiResponse<object?>.Fail(errorMessage);
    }
}
